var t = require;
var e = module;
var o = exports;
var n =
    (this && this.__extends) ||
    (function () {
        var t = function (e, o) {
            return (t =
                Object.setPrototypeOf ||
                ({__proto__: []} instanceof Array &&
                    function (t, e) {
                        t.__proto__ = e;
                    }) ||
                function (t, e) {
                    for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
                })(e, o);
        };
        return function (e, o) {
            function n() {
                this.constructor = e;
            }
            t(e, o), (e.prototype = null === o ? Object.create(o) : ((n.prototype = o.prototype), new n()));
        };
    })();
Object.defineProperty(o, "__esModule", {value: !0});
var r = t("Platforms"),
    a = t("Popup"),
    i = t("TableRules"),
    s = (function (t) {
        function e() {
            return (null !== t && t.apply(this, arguments)) || this;
        }
        return (
            n(e, t),
            (e.prototype.init = function () {
                (this.bottom = this.node.getChildByName("bottom")),
                    this.bottom.getChildByName("black").on(cc.Node.EventType.TOUCH_END, function () {}),
                    (this.disable = this.node.getChildByName("disable")),
                    this.disable.on(cc.Node.EventType.TOUCH_END, function () {}),
                    (this.stack = []);
                for (var t = 0, e = this.node.children; t < e.length; t++) {
                    var o = e[t];
                    switch (o) {
                        case this.bottom:
                        case this.disable:
                            continue;
                    }
                    var n = o.getComponent(a.Popup);
                    n ? n.init() : console.error("木有 Popup：" + o.name);
                }
            }),
            (e.prototype.getPopup = function (t) {
                for (var e = 0, o = this.node.children; e < o.length; e++) {
                    var n = o[e];
                    switch (n) {
                        case this.bottom:
                        case this.disable:
                            continue;
                    }
                    var r = n.getComponent(t);
                    if (r) return r;
                }
                return console.error("木有 " + t), null;
            }),
            (e.prototype.show = function (t) {
                var e = this,
                    o = this.getPopup(t);
                if (o) {
                    var n = this.stack.indexOf(o);
                    if (n > -1) {
                        if (n == this.stack.length - 1);
                        else {
                            var a = this.stack[this.stack.length - 1];
                            (this.stack[this.stack.length - 1] = o),
                                (this.stack[n] = a),
                                a.node.setSiblingIndex(n),
                                o.node.setSiblingIndex(this.stack.length);
                        }
                    } else
                        (this.disable.active = !0),
                            r.default.delays.clear(o.node.name + "_hideComplete"),
                            "hide" == o.__status && this.hideComplete(o),
                            0 == this.stack.length
                                ? (cc.Canvas.instance.node.emit("弹出"),
                                  (this.bottom.active = !0),
                                  (this.bottom.opacity = 0),
                                  this.bottom.stopAllActions(),
                                  this.bottom.runAction(cc.fadeIn(0.5)))
                                : this.bottom.setSiblingIndex(this.stack.length),
                            this.stack.push(o),
                            o.node.stopAllActions(),
                            o.node.setSiblingIndex(this.stack.length),
                            (o.node.active = !0),
                            (o.node.y = -100),
                            (o.node.opacity = 0),
                            (o._hide = function (t) {
                                e.hide(t);
                            }),
                            o.show(),
                            i.TableRules.show(o.node, "扩展" + o.node.name),
                            o.node.runAction(cc.fadeIn(0.5)),
                            o.node.runAction(
                                cc.sequence(
                                    cc.moveTo(0.5, 0, 0).easing(cc.easeBackOut()),
                                    cc.callFunc(function () {
                                        e.showComplete(o);
                                    })
                                )
                            );
                }
                return o;
            }),
            (e.prototype.showComplete = function (t) {
                (this.disable.active = !1), t.showComplete(), i.TableRules.show(t.node, t.node.name);
            }),
            (e.prototype.hide = function (t) {
                var e = this,
                    o = this.stack.indexOf(t);
                if (o > -1) {
                    (this.disable.active = !0),
                        this.stack.splice(o, 1),
                        this.stack.length > 0
                            ? this.bottom.setSiblingIndex(this.stack.length - 1)
                            : (this.bottom.stopAllActions(),
                              this.bottom.runAction(
                                  cc.sequence(
                                      cc.fadeOut(0.3),
                                      cc.callFunc(function () {
                                          (e.bottom.active = !1), cc.Canvas.instance.node.emit("弹出");
                                      }, this)
                                  )
                              ));
                    var n = function () {
                        t.node.stopAllActions(),
                            t.node.runAction(cc.fadeOut(0.3)),
                            t.node.runAction(
                                cc.sequence(
                                    cc.moveTo(0.3, 0, -100).easing(cc.easeBackIn()),
                                    cc.callFunc(function () {
                                        e.hideComplete(t);
                                    }, e)
                                )
                            ),
                            i.TableRules.hide(t.node, t.node.name);
                    };
                    r.default.delays.clear(t.node.name + "_hideComplete"),
                        "show" == t.__status
                            ? (this.showComplete(t),
                              r.default.delays.delay({
                                  time: i.TableRules.delayShowTime,
                                  action: n,
                                  group: t.node.name + "_hideComplete"
                              }))
                            : n();
                }
            }),
            (e.prototype.hideComplete = function (t) {
                (t.node.active = !1),
                    (this.disable.active = !1),
                    t.hideComplete(),
                    i.TableRules.hide(t.node, "扩展" + t.node.name);
            }),
            e
        );
    })(cc.Component);
o.default = s;
